<?php
namespace Api\Controller;
use Api\Controller\CommonController;
class IndexController extends CommonController {
    public function index(){
    	file_put_contents("/tryine/www/fleet/debug1.txt", 6666);
    	$id=$_GET['id'];
    	$asyntask=M('asyntask');
    	$data=$asyntask->alias('a')->join("__TASK__  b ON a.task_id=b.id")->where(['a.id'=>$id])->find();
    	$sort=json_decode($data['sort']);
    	 //发送通知
        require_once APP_PATH . "Common/Lib/push/sdk.php";
        $message = array(
            // 消息的标题.
            'title' => '有一个新任务，请注意查看',
            // 消息内容
            'description' => "运输：" . $data['task_from'] . '到' . $data['task_end'] . $data['total_load'] . '方',
            "custom_content"=> array("type"=>"1",'task_id'=>$id)
        );
        // 设置消息类型为 通知类型.
        $opts = array(
            'msg_type' => 1
        );
        
        // 创建SDK对象.
        $sdk = new \PushSDK();
        // 向目标设备发送一条消息
        $rs = $sdk->pushMsgToSingleDevice($sort[0]['channel_id'], $message, $opts);
        array_shift($sort);
        $asyntask->where(['id'=>$id])->save(['sort'=>json_encode($sort)]);
    }

}